import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src')
    }
  },
  server: {
    port: 5050, // 前端项目运行端口
    proxy: {
     // 配置代理规则，这里以 "/api" 为前缀举例
   '/api/sys': {
     target: 'http://localhost:6005', // 目标接口域名
     changeOrigin: true, // 允许跨域
     rewrite: (path) => path.replace(/^\/api\/sys/, ''), // 移除请求路径中的 "/api/product/" 前缀
     // 如果是https接口，需要配置这个参数
     secure: false
   },
   '/api/user': {
     target: 'http://localhost:6006', // 目标端口2
     changeOrigin: true,
     rewrite: (path) => path.replace(/^\/api\/user/, ''), // 移除 "/api/user/" 前缀
     secure: false
   },
   '/api/order': {
     target: 'http://localhost:6009', // 目标端口3
     changeOrigin: true,
     rewrite: (path) => path.replace(/^\/api\/order/, ''), // 移除 "/api/order/" 前缀
     secure: false
   },
   '/api/product': {
   target: 'http://localhost:6004', // 目标端口4
   changeOrigin: true,
   rewrite: (path) => path.replace(/^\/api\/product/, ''), // 移除 "/api/order/" 前缀
   secure: false
   },
   '/api/message': {
   target: 'http://localhost:6002', // 目标端口4
   changeOrigin: true,
   rewrite: (path) => path.replace(/^\/api\/message/, ''), // 移除 "/api/order/" 前缀
   secure: false
  }}

  },
  build: {
    outDir: 'dist',
    assetsDir: 'assets'
  }
})
